server {
    listen 8001;
    
    lua_code_cache off;  

    location /lua {
        default_type 'text/plain';

        # content_by_lua '
        #     ngx.say("<p>Hello, wmg!</p>")
        # ';

        lua_code_cache off;  

        content_by_lua_block {
            ngx.say('hello')
        }   
    }

     location /lua_request{
         default_type 'text/html';
         lua_code_cache off;
         content_by_lua_file  /usr/local/openresty/openrestyConfig/lua/lua_request.lua;
     }

    location ~ /lua_request2/(\d+)/(\d+) {  
        #设置nginx变量  
        set $a $1;   
        set $b $host;  
        default_type "text/html";  
        #nginx内容处理  
        content_by_lua_file /usr/local/openresty/openrestyConfig/lua/test_request2.lua;  
        #内容体处理完成后调用  
        echo_after_body "ngx.var.b $b";  
    }  


    location /lua_access {  
        default_type application/json;  
        access_by_lua_file /usr/local/openresty/openrestyConfig/lua/access_01.lua;  
        echo "access";  
    }  

    location @client {
        lua_code_cache off;  
        access_by_lua_file /usr/local/openresty/openrestyConfig/lua/access.lua;  
    }

    location /lua_sum{
        
        lua_code_cache off;  
        # 只允许内部调用
        internal;
        # 这里做了一个求和运算只是一个例子，可以在这里完成一些数据库、
        # 缓存服务器的操作，达到基础模块和业务逻辑分离目的
        content_by_lua_block {
            local args = ngx.req.get_uri_args()
            ngx.say(tonumber(args.a) + tonumber(args.b))
        }
    }

    location = /lua_sum_test {
        default_type 'text/html';
        lua_code_cache off;  
        content_by_lua_block {
            local res = ngx.location.capture("/lua_sum", {args={a=3, b=8}})
            ngx.say("status:", res.status, " response:", res.body)
        }  
    }



}  